//
//  AccidentAndMemberVIew.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/1/24.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class AccidentAndMemberView: UIView {
    // 航空意外险开关
    public let uiSwitch = UISwitch()
    // 添加乘机人
    private let addPassengerBtn = UIButton()
    // 出行温馨提示
    private let airline = UILabel(title: "温馨提示语",color: UIColor.black)
    // 航空意外险
    private let accidentText = UILabel(title: "航空意外险",color: UIColor.black)
    // 航空意外险提示
    private let accidentTip = UILabel(title: "¥30/航段/人",color: COLOR_NICE,size: 13,align: .right)
    // 保险广告语
    private let advertise = UILabel(title: "你若安好，我就备胎到老；你若不好，我是救命稻草。",color: UIColor.gray,size: 13)
    // 出行温馨提示 提示
    private let airlineTip = UILabel(title:"请至少提前一个小时到达航站楼，起飞前30分钟停止办理登机牌与托运服务。",color: UIColor.gray,size: 13)
    
    // 回调
    public var complete: (() -> Void)?
    public var completeSwitch: ((_ isOn:Bool) -> Void)?
    
    override func layoutSubviews() {
        // 航空意外险
        accidentText.frame = CGRect(x: MARGIN, y: 0, width: MARGIN100, height: MARGIN60)
        accidentText.font = UIFont.boldSystemFont(ofSize: 17)
        addSubview(accidentText)
        // 航空意外险开关
        let uiSize = uiSwitch.bounds.size
        uiSwitch.onTintColor = UIColor.orange
        uiSwitch.frame.origin = CGPoint(x: frame.width - MARGIN - uiSize.width, y: (MARGIN60 - uiSize.height) * 0.5)
        addSubview(uiSwitch)
        uiSwitch.addTarget(self, action: #selector(clickSwichItem(ui:)), for: .valueChanged)
        // 航空意外险提示
        let tipWidth = MARGIN100 + uiSize.width + MARGIN25
        accidentTip.frame = CGRect(x: frame.width - tipWidth, y: 0, width: MARGIN100, height: MARGIN60 + 3)
        addSubview(accidentTip)
        // 下划线
        let line = UIView()
        line.backgroundColor = COLOR_BACKGROUND
        line.frame = CGRect(x: MARGIN, y: MARGIN60, width: SCREEN_WIDTH - MARGIN * 2, height: 1)
        addSubview(line)
        // 保险广告语
        advertise.numberOfLines = 2
        advertise.frame = CGRect(x: MARGIN, y: line.frame.maxY, width: SCREEN_WIDTH - MARGIN * 2, height: MARGIN60)
        addSubview(advertise)
        // 空白
        let line2 = UIView()
        line2.backgroundColor = COLOR_BACKGROUND
        line2.frame = CGRect(x: 0, y: advertise.frame.maxY, width: SCREEN_WIDTH, height: MARGIN10)
        addSubview(line2)
        // 出行温馨提示
        airline.numberOfLines = 2
        airline.font = UIFont.boldSystemFont(ofSize: 17)
        airline.frame = CGRect(x: MARGIN, y: line2.frame.maxY, width: SCREEN_WIDTH - MARGIN * 2, height: MARGIN60)
        addSubview(airline)
        // 下划线
        let line3 = UIView()
        line3.backgroundColor = COLOR_BACKGROUND
        line3.frame = CGRect(x: MARGIN, y: airline.frame.maxY, width: SCREEN_WIDTH - MARGIN * 2, height: 1)
        addSubview(line3)
        // 出行温馨提示 提示
        airlineTip.numberOfLines = 2
        airlineTip.frame = CGRect(x: MARGIN, y: line3.frame.maxY, width: SCREEN_WIDTH - MARGIN * 2, height: MARGIN60)
        addSubview(airlineTip)
    }
    
    @objc func clickSwichItem(ui:UISwitch) -> Void {
        if let callback = completeSwitch {
            callback(ui.isOn)
        }
    }
}
